<template>
    <H1>登录页面</H1>

    <table>
        <tr>
            <td>账号</td>
            <td>
                <input type="text" v-model="Name"  />
            </td>
        </tr>

        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="Pwd" />
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="登录" @click="Login" />
            </td>
        </tr>
    </table>

</template>

<script setup lang="ts">

import {ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router = useRouter()

const Name = ref('')
const Pwd = ref('')

function Login() {
    axios({
        method:'get',
        url:'http://localhost:62821/api/Default/Login',
        params:{
            Name:Name.value,
            Pwd:Pwd.value
        }
    })
    .then(function (res) {
        if(res.data>0){
            alert('登录成功');
            router.push('/ShowLogin')
        }
        else if(res.data==-1){
            alert('账号不存在,请重新输入');
            return;
        }
        else if(res.data==-2){
            alert('账号密码不匹配');
            return;
        }
        else{
            alert('登录失败');
            return;
        }
    })
    .catch(function (error) {
        console.log(error)
    })
}

</script>
